import { STable, Ellipsis } from '@/views/box/components'
export const listMixin = {
  data () {
    return {
      paginationProps: {
        total: 0,
        showTotal: total => `共有 ${total} 条数据`
      },
      queryParam: {},
      /* table选中keys*/
      selectedRowKeys: [],
      /* table选中records*/
      selectionRows: [],
      /* 排序参数 */
      isorter: {
        column: 'createTime',
        order: 'desc',
      },
      /* 筛选参数 */
      filters: {},
      /* table加载状态 */
      loading: false,
    }
  },
  components: {
    STable,
    Ellipsis
  },
  methods: {
    // 查询列表
    fetchList (params, getList) {
      return new Promise((resolve, reject) => {
        getList(params).then(res => resolve(res)).catch(err => reject(err))
      })
    },
    // 搜索列表
    searchList () {
      this.$refs.table.refresh(true)
    },
    // 重置列表
    resetList () {
      this.queryParam = {}
      this.$refs.table.refresh(true)
      this.onClearSelected()
    },
    // 刷新列表
    refreshList () {
      this.$refs.table.refresh()
    },
    // 清空列表选中
    onClearSelected () {
      this.selectedRowKeys = [];
      this.selectionRows = [];
    },
    // 新增/编辑 弹窗
    handleEditModal (arg) {
      this.$refs.modalForm.show(arg);
      // this.$refs.modalForm.title = "新增";
      // this.$refs.modalForm.disableSubmit = false;
    },
    // 新增/编辑
    handleEdit (path) {
      this.$router.push(path)
    },
    // 删除
    handleDelete (params, deleteBatch) {
      deleteBatch(params).then(res => {
        if (res.code == 0) {
          this.$message.success('删除成功！')
        } else {
          this.$message.warning(res.msg)
        }
      })
    },
    filterFields (values) {
      const formValue = {}
      Object.keys(values).forEach(i => {
        if (values[i] !== '' && values[i] !== undefined && values[i] !== null) {
          formValue[i] = values[i]
        }
      })
      return formValue
    },
  },
}